/** TestSource.cpp
*
*  Created by Penrillian, Smartphone Software Innovators 
*  See http://www.penrillian.com
*/

#include "TestHeader.h"
#include "TestDriver.h"
#include "Logger.h"

#include <xmlrpc.h>

using namespace XmlRpc;

void CTypeTest::testCIntL()
	{
	RBuf8 buf;

	CInt* i = CInt::NewL(52);
	i->AppendXmlToBufL(buf);
	_LIT8(KCIntString, "<int>52</int>");
	delete i;
	
	TS_ASSERT_EQUALS(buf.Compare(KCIntString()), 0);
	buf.Close();
	}

void CTypeTest::testCBooleanL()
	{
	RBuf8 buf;
	CBoolean* b = CBoolean::NewL(ETrue);
	b->AppendXmlToBufL(buf);
	delete b;

	_LIT8(KCBoolString, "<boolean>1</boolean>");
	TS_ASSERT_EQUALS(buf.Compare(KCBoolString()), 0);
	buf.Close();
	}

void CTypeTest::testCDoubleL()
	{
	RBuf8 buf;
	CDouble* d = CDouble::NewL(3.141592);
	d->AppendXmlToBufL(buf);
	delete d;
	_LIT8(KCDoubleString, "<double>3.141592</double>");
	TS_ASSERT_EQUALS(buf.Compare(KCDoubleString()),0);
	buf.Close();
	}

void CTypeTest::testCDateTimeL()
	{
	RBuf8 buf;
	CDateTime* t = CDateTime::NewL(TDateTime(1984, EFebruary, 5, 3, 14, 15, 0));
	t->AppendXmlToBufL(buf);
	delete t;
	_LIT8(KCDateString, "<dateTime.iso8601>19840206T03:14:15</dateTime.iso8601>");
	TS_ASSERT_EQUALS(buf.Compare(KCDateString()), 0);
	buf.Close();
	}

void CTypeTest::testCStringL()
	{
	RBuf8 buf;
	_LIT(KCStringTest, "CString Test");
	CString* s = CString::NewL(KCStringTest());
	s->AppendXmlToBufL(buf);
	delete s;
	_LIT8(KCStringString, "<string>CString Test</string>");
	TS_ASSERT_EQUALS(buf.Compare(KCStringString()), 0);
	buf.Close();
	}

void CTypeTest::testCBase64L()
	{
	RBuf8 buf;
	_LIT8(KB64TestData, "foobar");
	CBase64* b64 = CBase64::NewL(KB64TestData);
	b64->AppendXmlToBufL(buf);
	delete b64;

	_LIT8(KCBase64String, "<base64>Zm9vYmFy</base64>");
	TS_ASSERT_EQUALS(buf.Compare(KCBase64String()), 0);
	buf.Close();
	}

void CTypeTest::testCArrayL()
	{
	RBuf8 buf;
	CArray* a = CArray::NewL();
	_LIT8(KB64TestData, "foobar");
	CBase64* b64 = CBase64::NewL(KB64TestData);
	a->AppendL(b64);
	CInt* i = CInt::NewL(342);
	a->AppendL(i);
	a->AppendXmlToBufL(buf);
	delete a;

	_LIT8(KCArrayString, "<array><data><value><base64>Zm9vYmFy</base64></value><value><int>342</int></value></data></array>");
	TS_ASSERT_EQUALS(buf.Compare(KCArrayString()), 0);
	buf.Close();
	}

void CTypeTest::testCStructL()
	{
	RBuf8 buf;
	_LIT8(KField1, "foobar");
	_LIT8(KField2, "doodaa");
	CStruct* st = CStruct::NewL();
	_LIT8(KB64TestData, "foobar");
	CBase64* b64 = CBase64::NewL(KB64TestData);
	st->SetL(KField1(), b64);
	CInt* i = CInt::NewL(342);
	st->SetL(KField2(), i);
	st->AppendXmlToBufL(buf);
	delete st;
	_LIT8(KCStructString, "<struct><member><name>doodaa</name><value><int>342</int></value></member>"
		"<member><name>foobar</name><value><base64>Zm9vYmFy</base64></value></member></struct>");
	TS_ASSERT_EQUALS(buf.Compare(KCStructString()), 0);
	buf.Close();
	}


